'# QUOTE : Returns a quoted string 
function Quote (StringToQuote as string) as string
StringToQuote =  chr$(34) + StringToQuote + chr$(34)
result = replacesubstr$(stringtoquote, chr$(34) + chr$(34), chr$(34))
end function

'=============================================================================== 
'# STRIPPATH : Returns file path (without file name) 
Function StripPath (fullname as string) as string
result = left$(fullname, rinstr(fullname, "\"))
end function

'=============================================================================== 
'# STRIPFILENAME : Returns file name (without path) 
Function StripFileName (fullname as string) as string
result = right$(fullname, len(fullname) - rinstr(fullname, "\"))
end function

'=============================================================================== 
'# STRIPFILEEXT : Returns file extension (like ".exe", ".html" etc.) 
Function StripFileExt (fullname as string) as string
result = right$(fullname, len(fullname) - rinstr(fullname, ".") + 1)
end function

'=============================================================================== 
'# FILENAMENOEXT : Returns file name without extension 
function FileNameNoExt(fullname as string) as string
fullname = right$(fullname, len(fullname) - rinstr(fullname, "\"))
result = left$(fullname, rinstr(fullname, ".") - 1)
end function

'=============================================================================== 
'# FULLPATHNOEXT : Returns full path without file extension 
function FullPathNoExt(fullname as string) as string
result = left$(fullname, rinstr(fullname, ".") - 1)
end function

'=============================================================================== 
'# C_Style : Returns "slashed" path from a "backslashed" one 
function C_Style (fullname as string) as string
fullname = replacesubstr$(fullname, "\\", "\")
result = replacesubstr$(fullname, "\", "/")
end function

'=============================================================================== 
'# SYSDIR : Retrieves windows shell directories 

'-------------------------| 
' Allowed values for dir  | 
'-----------------------------------------------------------------------------| 
' Desktop                 | Templates               | AppData                 | 
' Start Menu              | Programs                | Startup                 | 
' Fonts                   | SendTo                  | Recent                  | 
' Favorites               | Cache                   | Cookies                 | 
' History                 | NetHood                 | Personal                | 
' PrintHood               | Local AppData           | My Pictures             | 
' Administrative Tools    |                         |                         | 
'-----------------------------------------------------------------------------| 

function SysDir (dir as string) as string
DIM fo_reg AS QRegistry
fo_reg.RootKey = &H80000001
fo_reg.openkey ("Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", 0)
result = fo_reg.readstring(dir) + "\"
end function

'=============================================================================== 
'# HOMEDIR : The folder where the application is 

function homedir() as string
result = left$(command$(0), rinstr(command$(0), "\"))
end function

'=============================================================================== 
'# BROWSEFORFOLDERS : Returns the selected folder 

function BrowseForFolders (initialdir as string, wincapt as string) as string
dim bff_form as qform
with bff_form
.height = 400
.center
.caption = wincapt
.delbordericons 2
end with
dim bff_tree as qdirtree
with bff_tree
.parent = bff_form
.align = 5
end with
if bff_form.caption = "" then bff_form.caption = "Select folder"
if direxists(initialdir) then
bff_tree.directory = initialdir
else
bff_tree.directory = curdir$
end if
bff_form.showmodal
result = bff_tree.directory
end function

'=============================================================================== 
'# BROWSEFORFILE : Returns the selected folder 

Function BrowseForFile (caption as string, filter as string, _
initialdir as string) as string

dim bff_od as qopendialog
with bff_od
.caption = caption
.filter = filter
.initialdir = initialdir

if .execute then
    result = .filename
end if
end with

end function